package cn.com.yx.ms.service.impl;

import cn.com.yx.ms.application.web.ApiPager;
import cn.com.yx.ms.application.web.ApiQueryBase;
import cn.com.yx.ms.domain.TestModel;
import cn.com.yx.ms.persistence.TestMapper;
import cn.com.yx.ms.service.ITestService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * ApphubServiceImpl
 */
@Service
@Transactional
public class TestServiceImpl implements ITestService {

    @Resource
    private TestMapper testMapper;

    @Override
    public TestModel findOne(String id) {
        System.out.println("无缓存时走这里...");
        return testMapper.findOne(id);
    }

    @Override
    public int insert(TestModel testModel) {
        return testMapper.insert(testModel);
    }

    @Override
    public int delete(String id) {
        return testMapper.delete(id);
    }

    @Override
    public int update(TestModel testModel) {
        return testMapper.update(testModel);
    }

    @Override
    public ApiPager<TestModel> find(ApiQueryBase query) {

        PageHelper.startPage(query.getPi(), query.getPs(), true);
        Page<TestModel> page = (Page<TestModel>) testMapper.find(query);

        ApiPager<TestModel> apiPager = new ApiPager<TestModel>(query.getPs(),
                query.getPi(),
                page.getTotal(),
                page.getResult());
        return apiPager;//ApiResult.success(AppConstant.MSG_SUCCESS, apiPager);

    }

}